var url = location.search; //获取url中"?"符后的字串 ('?modFlag=business&role=1')
 var theRequest = new Object();
 var flag ='';
 if (url.indexOf('?') != -1) {
	 var str = url.substr(1); //substr()方法返回从参数值开始到结束的字符串；
	 var strs = str.split('&');
		 for (var i = 0; i < strs.length; i++) {
		    theRequest[strs[i].split('=')[0]] = strs[i].split('=')[1]
		 }
		 flag=theRequest.flag; //此时的theRequest就是我们需要的参数；
		 console.log(flag)
 }

$(function(){
	$.ajax({
		url:'../userController/getUser',
		success:function(data){
			console.log(data)
			if(flag==1){
				$(".recordPice").html("￥"+data.balance.toFixed(2)+"元")
			}else{
				$(".recordPice").html("￥"+data.mBalance.toFixed(2)+"元")
			}
			
			if(data.zfb_name!=null || data.zfb_name!=""){
				$("#zfb_name").val(data.zfb_name);
			}
			if(data.zfb_number!=null || data.zfb_number!=""){
				$("#zfb_number").val(data.zfb_number);
			}
		}
	})
})

$(".submit").click(function(){
	var price=$("#price").val();
	var zfb_number=$("#zfb_number").val();
	var zfb_name=$("#zfb_name").val();
	if(price=="" || price==null){
		alert("请输入金额");
	}else if(zfb_number=="" || zfb_number==null){
		alert("请输入支付宝账号");
	}else if(zfb_name=="" || zfb_name==null){
		alert("请输入支付宝昵称");
	}else{
		$(".submit").unbind("click");
		$.ajax({
			url:'../orderController/withDrawal',
			data:{
				"zfb_number":zfb_number,
				"zfb_name":zfb_name,
				"price":price,
				"flag":flag
			},
			success:function(data){
				alert(data);
				$(".submit").bind("click");
				if(flag==1){
					window.location.href="../html/core.html"
				}else{
					window.location.href="../html/myBao.html"
				}
			},
			error:function(){
				alert("加载失败")
			}
		})
	}
})

$(function(){
	$.ajax({
		url:'../nameController/getRules',
		success:function(data){
			console.log(data);
			$(".rule").html(data.remark2);
		}
	})
})